home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NETWORK.SWG / 0016_Novell Name.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  4KB  |  117 lines

  1. {
  2. >To anyone that can help me, this is my problem: I want to program a simple
  3. >E-Mail program for Novel Network v2.1.  But i have one problem.  While in
  4. >a pascal programmed program, how do i find out the user login name
  5. >automatically?
  6.  
  7. I tested this code on Novell 3.11, but the API calls should also work on your
  8. 2.1 network.  The login time is also available as a by-product.
  9. }
  10.  
  11. program ShowUser;
  12.  
  13. uses Dos;
  14.  
  15. type
  16.   NovTime = record
  17.     LoginYear  : byte;       { 0 to 99; if < 80, year is in 21st century }
  18.     LoginMonth : byte;       { 1 to 12 }
  19.     LoginDay   : byte;       { 1 to 31 }
  20.     LoginHour  : byte;       { 0 to 23 }
  21.     LoginMin   : byte;       { 0 to 59 }
  22.     LoginSec   : byte;       { 0 to 59 }
  23.     LoginDOW   : byte;       { 0 to 6, 0 = Sunday, 1 = Monday ... }
  24.   end;
  25.  
  26.  
  27. { GetConnInfo --------------------------------------------------------------}
  28. { -----------                                                               }
  29.  
  30. function GetConnInfo(     Connection : Byte;
  31.                       var ConnName   : string;
  32.                       var ConnTime   : NovTime ) : Byte;
  33. VAR
  34.   NameArray : array[ 0..48 ] of Byte absolute ConnName;
  35.   NovRegs   : Registers;
  36.  
  37.   Request : record
  38.     Len   : Word;
  39.     Func  : Byte;
  40.     Conn  : Byte
  41.   end;
  42.  
  43.   Reply    : record
  44.     Len    : Word;
  45.     ID     : Longint;
  46.     Obj    : Word;                        { Object type }
  47.     Name   : array[ 1..48 ] of Byte;
  48.     Time   : NovTime;
  49.     Filler : Byte       { Isn't in my Novell docs, but won't work without!  }
  50.   end;
  51.  
  52.  
  53. begin
  54.   with Request do                      { Initialize request buffer:         }
  55.   begin
  56.     Len := 2;                                    { Buffer length,           }
  57.     Func := $16;                                 { API function,            }
  58.     Conn := Connection                           { Connection # to query    }
  59.   end;
  60.  
  61.   Reply.Len := SizeOf( Reply ) - 2;    { Initialize reply buffer length     }
  62.  
  63.   with NovRegs do
  64.   begin
  65.     AH := $E3;                         { Connection Services API call       }
  66.     DS := Seg( Request );              { Location of request buffer         }
  67.     SI := Ofs( Request );
  68.     ES := Seg( Reply );                { Location of reply buffer           }
  69.     DI := Ofs( Reply );
  70.     MsDos( NovRegs );                  { Make the call                      }
  71.     GetConnInfo := AL                  { Completion code is function result }
  72.   end;
  73.  
  74.   with Reply do
  75.   begin
  76.     Obj := Swap( Obj );                          { If object is a user and  }
  77.     if ( Obj = 1 ) and ( NovRegs.AL = 0 ) then   {   call was successful,   }
  78.     begin
  79.       ConnTime := Time;                          { Return login time        }
  80.       Move( Name, NameArray[ 1 ], 48 );          { Convert ASCIIZ to string }
  81.       NameArray[ 0 ] := 1;
  82.       while ( NameArray[ NameArray[ 0 ] ] <> 0 )
  83.             and ( NameArray[ 0 ] < 48 ) do
  84.         Inc( NameArray[ 0 ] );
  85.       Dec( NameArray[ 0 ] )
  86.     end
  87.   end
  88. end;
  89.  
  90.  
  91. { GetConnNo ----------------------------------------------------------------}
  92. { ---------                                                                 }
  93.  
  94. function GetConnNo : byte;
  95.  
  96. var
  97.   NovRegs : Registers;
  98.  
  99. begin
  100.   NovRegs.AH := $DC;
  101.   MsDos( NovRegs );
  102.   GetConnNo := NovRegs.AL
  103. end;
  104.  
  105.  
  106. { MAIN =====================================================================}
  107. { ====                                                                      }
  108.  
  109. var
  110.   UserName  : string;
  111.   LoginTime : NovTime;
  112.  
  113. begin
  114.   GetConnInfo( GetConnNo, UserName, LoginTime );
  115.   WriteLn( 'User''s name is ', UserName )
  116. end.
  117.